home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Graphics Samples / Dashing Text ƒ / dashing text.c next >
Encoding:
C/C++ Source or Header  |  1993-09-14  |  4.4 KB  |  148 lines  |  [TEXT/KAHL]

  1. /*
  2.     dashing text.c
  3.     
  4.     This file demonstrates dashing of text along a curve.
  5.     
  6.     NOTES:
  7.     • This file requires the following files to run correctly:
  8.         "graphics shell.c", "color library.c", "font library.c", "graphics debug library.c", "shape library.c",  
  9.         "transform library.c".
  10.         
  11.     • This file prints the "best" in landscape mode.
  12.      
  13.     ©1990 -1993  Apple Computer, Inc.
  14.     All rights reserved.
  15. */
  16.  
  17.  
  18. #include <events.h>
  19. #include <windows.h>
  20.  
  21. #include "font library.h"
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "graphics shell.h"
  25.  
  26. //
  27. //  Set up the title and size of the window 
  28. //
  29. Str255         gWindowTitle = "\p Dashing text";
  30. Rect         gWindowQDRect  = {50, 50, 240, 495};
  31.  
  32. //
  33. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  34. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  35. //    but these  functions will not work.
  36. //
  37. Boolean        gDebugging = true;
  38.  
  39.  
  40. //
  41. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  42. //
  43. Boolean        gGiveMeValidation = true;
  44.  
  45.  
  46. //
  47. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  48. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  49. //    With gGraphicsHeapSize set to 105k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  50. //
  51. long        gGraphicsHeapSize = 105;
  52.  
  53. gxShape     gDashingShape;
  54.  
  55.  
  56. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  57.  
  58. void DoInitialization(aWindow)
  59. WindowPtr aWindow;
  60. {
  61.     gxCurve         curvepts = {{ff(10),ff(100)},{ff(150), -ff(55)},{ff(410),ff(150)}};
  62.     gxDashRecord    textDash;
  63.  
  64.      InitCommonColors();
  65.     
  66.     //  
  67.     //     Create the text shape that will be dashed
  68.      //  
  69.     textDash.dash = GXNewText(24,(unsigned char*)"QuickDraw™ GX is beta 2! ",  nil);
  70.     SetShapeCommonFont(textDash.dash, timesFont);
  71.     GXSetShapeTextSize(textDash.dash, ff(35));
  72.  
  73.     //  
  74.     // Set up the dash record.  Things to note: 
  75.     //        • scale should equal the text size. This will make sure that the text is dashed to the size of the curve
  76.     //        • If you want the textDash to be only used once on the curve, the advance must be larger than the curve's
  77.     //           length. You could use GXGetShapeLength (gDashingShape, ...); to determine the length of the curve and use this
  78.     //           value for advance.
  79.     //  
  80.     textDash.attributes = gxBreakDash | gxAutoAdvanceDash;
  81.     textDash.advance = ff(330);
  82.      textDash.phase = 0;
  83.     textDash.scale = ff(35);
  84.  
  85.     GXSetShapeType(textDash.dash, gxPathType);
  86.      
  87.     //  
  88.      //     Create the gxCurve to be dashed to.
  89.     //  
  90.       gDashingShape = GXNewCurve(&curvepts);
  91.       GXSetShapePen(gDashingShape, ff(35));
  92.     SetShapeCommonColor (gDashingShape, blue);
  93.     
  94.     //  
  95.     //     Add the textDash to the style of the gDashingShape. Since, we are adjusting the gxStyle of our shape and
  96.     //    this shape currently references the "default" style, GX graphics will make a copy of the style
  97.     //    and attach it to our shape.
  98.     //  
  99.     GXMoveShapeTo (gDashingShape, ff(30), ff(130));
  100.     GXSetShapeDash (gDashingShape, &textDash);
  101.     GXDisposeShape(textDash.dash);  
  102.   }
  103.  
  104.  
  105. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  106.  
  107. void DoDraw(aWindow)
  108. WindowPtr aWindow;
  109. {
  110.     GXDrawShape (gDashingShape);
  111. }
  112.  
  113.  
  114. /*------ DoDispose -------------------------------------------------------------------------------------*/
  115.  
  116. void DoDispose(aWindow)
  117. WindowPtr aWindow;
  118. {
  119.     //  
  120.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  121.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  122.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  123.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  124.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  125.     //  
  126.     GXDisposeShape(gDashingShape);  
  127.      GXDisposeShape(gWindowBoundsShape);  
  128.        DisposeCommonColors();
  129.        DisposeWindow(aWindow);
  130. }
  131.     
  132.  
  133.  
  134. /*------ DoClick ---------------------------------------------------------------------------------------*/
  135.  
  136. void DoClick(aWindow)
  137. WindowPtr aWindow;
  138. {
  139. }
  140.  
  141.  
  142. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  143.  
  144. void DoIdle(aWindow)
  145. WindowPtr aWindow;
  146. {
  147. }
  148.